home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / DELPHI.SWG / 0024_How to use a popup menu with a VBX.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  920 b   |  29 lines

  1. {
  2. Q:  I want to be able to right click on my VBX and have     a
  3. popup menu display.  When I use a popup menu for the form, it
  4. shows no matter where I right click.  I want to just have it
  5. popup for right clicks on the vbx.
  6.  
  7. How do I trap for that?
  8.  
  9. A:  Here it is:
  10. }
  11.  
  12. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  13.   Shift: TShiftState; X, Y: Integer);
  14. begin
  15.   if button = mbRight then
  16.     with (Sender AS TControl) do
  17.       with ClientToScreen(Point(X,Y)) do
  18.       begin
  19.         PopupMenu1.PopupComponent := TComponent(Sender);
  20.         PopupMenu1.Popup(X,Y);
  21.       end;
  22. end;
  23.  
  24. Note: The form's PopupMenu property must be empty, or it will popup
  25. from everywhere.  If you want the form to be the only place showing
  26. the popup, place this method on the form's OnMouseDown event.  If
  27. you want the VBX to be the only place, then place it on the VBX's
  28. OnMouseDown event, etc.
  29.